//
//  UIBarbuttonItem+Button.swift
//  mxfweibo
//
//  Created by apple1 on 15/12/20.
//  Copyright © 2015年 莫祥富. All rights reserved.
//

import UIKit

extension UIBarButtonItem {
    
    //便利构造函数
    convenience init(imageName:String) {
        let hightlightedImageName = imageName + "_highlighted"
        
        let button = UIButton()
        button.setImage(UIImage(named: imageName), forState: UIControlState.Normal)
        button.setImage(UIImage(named: hightlightedImageName), forState: UIControlState.Highlighted)
        
        button.sizeToFit()
        self.init(customView:button)
    }
  
    //创建UIBarButtonItem类方法
    class func createBarButtonItem (imageName:String) ->UIBarButtonItem {
        
        let hightlightedImageName = imageName + "_highlighted"
        
        let button = UIButton()
        button.setImage(UIImage(named: imageName), forState: UIControlState.Normal)
        button.setImage(UIImage(named: hightlightedImageName), forState: UIControlState.Highlighted)
        
        button.sizeToFit()
        
        return UIBarButtonItem(customView: button)
    }
    
}



